<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>timer-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="comment">/*</span>
<span class="comment"> * $Id: timer-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/** \file timer.h</span>
<span class="comment"> * \brief Additional timers for ROBOTC.</span>
<span class="comment"> *</span>
<span class="comment"> * timer.h provides additional timers for ROBOTC.  Please note that there is no</span>
<span class="comment"> * roll-over checking done at all.  That means that if the program runs for more than</span>
<span class="comment"> * around 596 hours, it will roll over and weird stuff will happen.</span>
<span class="comment"> *</span>
<span class="comment"> * The default number of timers is 10, but this can be changed by defining MAX_TIMERS</span>
<span class="comment"> * before this driver is included.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * \date 18 May 2010</span>
<span class="comment"> * \version 0.1</span>
<span class="comment"> * \example TMR-test1.c</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="timer_8h.html" title="Additional _timers for ROBOTC.">drivers/timer.h</a>&quot;</span>

task main () {

  <span class="comment">// Create two new timer index numbers</span>
  <span class="keywordtype">int</span> timer1 = <a name="a0"></a><a class="code" href="group__tmr.html#gab7dee3d8e9d3a5238f9783c7128c0133">TMRnewTimer</a>();
  <span class="keywordtype">int</span> timer2 = <a class="code" href="group__tmr.html#gab7dee3d8e9d3a5238f9783c7128c0133">TMRnewTimer</a>();

  <span class="comment">// Configure timer1 for 2000ms</span>
  <a name="a1"></a><a class="code" href="group__tmr.html#ga997561cae0ac2e4e913cc05de85f96cc">TMRsetup</a>(timer1, 2000);

  <span class="comment">// Configure timer2 for 5000ms</span>
  <a class="code" href="group__tmr.html#ga997561cae0ac2e4e913cc05de85f96cc">TMRsetup</a>(timer2, 5000);

  <span class="comment">// Reset and start both timers</span>
  <a name="a2"></a><a class="code" href="group__tmr.html#ga606c8dd6ba44f2b8ba511222f77c6a8c">TMRreset</a>(timer1);
  <a class="code" href="group__tmr.html#ga606c8dd6ba44f2b8ba511222f77c6a8c">TMRreset</a>(timer2);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// If timer1 expires, make a small noise and reset it.</span>
    <span class="keywordflow">if</span> (<a name="a3"></a><a class="code" href="group__tmr.html#gab78c56419d4f5ed99df72510202238ad">TMRisExpired</a>(timer1)) {
      PlaySound(soundBlip);
      <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
      <a class="code" href="group__tmr.html#ga606c8dd6ba44f2b8ba511222f77c6a8c">TMRreset</a>(timer1);
    }

    <span class="comment">// If timer2 expires, make a small noise and reset it.</span>
    <span class="keywordflow">if</span> (<a class="code" href="group__tmr.html#gab78c56419d4f5ed99df72510202238ad">TMRisExpired</a>(timer2)) {
      PlaySound(soundShortBlip);
      <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
      <a class="code" href="group__tmr.html#ga606c8dd6ba44f2b8ba511222f77c6a8c">TMRreset</a>(timer2);
    }
    EndTimeSlice();
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: timer-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
